package com.dhnsoft.web.controller;

import com.dhnsoft.web.entity.Person;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-08-24 17:08
 * @Desc
 */
@RestController
public class HelloController {

    @GetMapping("h")
    public Person hello(){
        Person person = new Person();
        person.setId(1L);
        person.setAge(24);
        person.setUsername("dhn");
        person.setEmail("9132@qq.com");
        return person;
    }

    public static void aa(String[] args) throws JsonProcessingException {
        Person person = new Person();
        person.setId(1L);
        person.setAge(24);
        person.setUsername("dhn");
        person.setEmail("9132@qq.com");
        //禁用自带的---
        YAMLFactory factory = new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
        ObjectMapper mapper = new ObjectMapper(factory);
        String s = mapper.writeValueAsString(person);
        System.out.println(s);
    }
}
